
/* -----------------
* brief 
* 1. this is code gen by tools 
* 2. array like [a,b,c] after each field, define the ui html tag in view, 
		a for title, 
		b for show or not , (onlyread is trial feature)
		c for element html tag , currently support : check、radio、select、input、textarea、upload
* 3. XXX
*/
//go:generate legogen -type=MchMemberCard -kv=ModuleName=merchantCard,PrjName=saas_sys_base -dirconf=../../.. ./MchMemberCard.go

/*使用方法一(go generate)：在工程root目录下，执行go generate ./modules/merchantCard/models

使用方法二(legogen)：直接调用生成命令
legogen -type=MchMemberCard -kv=ModuleName=merchantCard,PrjName=saas_sys_base -dirconf=./. ./modules/merchantCard/models/MchMemberCard.go
*/

package merchantCard

import (
	wxcard "github.com/chanxuehong/wechat/mp/card"
	"github.com/mjiulee/lego"
	"saas_sys_base/common"
)

func init() {
	lego.AddBeanToSynList(new(MchMemberCard))
}

/* table: "tb_mch_member_card"
 * -----------------
*/
const TB_MCH_MEMBER_CARD = "tb_mch_member_card"

type MchMemberCard struct {
	Id        int64  `xorm:"pk" json:",string"`                  // ["id","hide","hidden"]
	IfDel     int `xorm:"default 0"` // ["deleted","hide","hidden"]
	Cdate     string `xorm:"DateTime created"`    // ["create","show","datetime"]
	Udate     string `xorm:"DateTime updated"`    // ["update","show","datetime"]
    // add your custom field here

	common.Who `xorm:"extends"` //["Who","show","input"]
	//WeappId string `xorm:"char(64) NOT NULL"` // ["微信APP ID","show","input"]
	CardMode CARDMODE `xorm:"" json:"card_mode"` // ["卡模式","show","input"]

	MchMemberCardAttr `xorm:"extends"`

	wxcard.MemberCard `xorm:"extends" json:"wx_member_card"` //注意：//CardId和Weappid放在MemberCard.CardBaseInfo里
	RefuseReason string `xorm:""` // ["审核拒绝理由","show","input"]



}


func NewMchMemberCard(who *common.Who, card *MchCardUnionMsg) *MchMemberCard{
	newitem := new(MchMemberCard)
	newitem.Who = *who
	newitem.CardMode = card.CardMode
	newitem.MemberCard = *card.Card.MemberCard
	if card.CardMode == CARD_MODE_MCH {
		newitem.MemberCard.BaseInfo.Status = wxcard.CardStatusVerifyOk //纯商户卡不需要审核
	} else {
		newitem.MemberCard.BaseInfo.Status = wxcard.CardStatusNotVerify
	}
	newitem.MemberCard.BaseInfo.CardId = card.Card.MemberCard.BaseInfo.CardId
	newitem.MemberCard.BaseInfo.AppId = card.Card.MemberCard.BaseInfo.AppId

	newitem.MchMemberCardAttr = *card.MchMemberCard
	return newitem
}